/*
 * @Description:
 * @Version: 2.0
 * @Author: godless
 * @Date: 2024-06-27 11:00:47
 * @LastEditors: godless
 * @LastEditTime: 2024-07-01 17:06:04
 */
const state = {
  sidebar: {
    opened: true, // 侧边栏是否展开
    withoutAnimation: false, // 侧边栏展开时是否有动画效果
  },
  device: "desktop", // 设备类型
};

const mutations = {
  // 设置侧边栏展开状态
  TOGGLE_SIDEBAR: (state) => {
    state.sidebar.opened = !state.sidebar.opened;
    state.sidebar.withoutAnimation = false;
  },
  // 收紧侧边栏
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    state.sidebar.opened = false;
    state.sidebar.withoutAnimation = withoutAnimation;
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device;
  },
};

const actions = {
  toggleSideBar({ commit }) {
    commit("TOGGLE_SIDEBAR");
  },
  closeSideBar({ commit }, { withoutAnimation }) {
    commit("CLOSE_SIDEBAR", withoutAnimation);
  },
  toggleDevice({ commit }, device) {
    commit("TOGGLE_DEVICE", device);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
